package com.xhwl.logistics.converter.mapstruct;

import com.xhwl.common.dto.cent.vehicle.feign.CreateVehicleAccessRecordForOutNanTouFeignDTO;
import com.xhwl.common.dto.cent.vehicle.feign.VehiclePayRecordQuery;
import com.xhwl.logistics.bo.input.QueryVehiclePayRecordForCountBO;
import com.xhwl.logistics.dto.query.CarPayJieShunDTO;
import com.xhwl.logistics.dto.query.PageDTO;
import com.xhwl.logistics.entity.VehiclePayRecord;
import com.xhwl.logistics.util.AboutDateUtil;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValueMappingStrategy;

import java.math.BigDecimal;
import java.util.Date;

@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
public interface VehiclePayRecordConverter {

    BigDecimal vehiclePayBigDecimal = new BigDecimal(100);

    //*********feign*********
    @Mapping(target = "accessRecordId", source = "recordId")
    VehiclePayRecord toVehiclePayRecord(CreateVehicleAccessRecordForOutNanTouFeignDTO createVehicleAccessRecordForOutNanTouFeignDTO, String recordId);

    @Mapping(target = "accessRecordId", source = "recordId")
    VehiclePayRecord toVehiclePayRecord(CreateVehicleAccessRecordForOutNanTouFeignDTO createVehicleAccessRecordForOutNanTouFeignDTO);

    //*********Data Push JieShun*********
    default VehiclePayRecord jieShun2VehiclePayRecord(CarPayJieShunDTO carPayJieShunDTO, Integer projectId) {
        VehiclePayRecord vehiclePayRecord = toVehiclePayRecord(carPayJieShunDTO, projectId);
        vehiclePayRecord.setTotalMoney(carPayJieShunDTO.getYsMoney().multiply(vehiclePayBigDecimal).intValue());
        vehiclePayRecord.setPaidMoney(carPayJieShunDTO.getSsMoney().multiply(vehiclePayBigDecimal).intValue());
        vehiclePayRecord.setFreeMoney(carPayJieShunDTO.getYhMoney().multiply(vehiclePayBigDecimal).intValue());
        return vehiclePayRecord;
    }

    @Mapping(source = "carPayJieShunDTO.parkCode", target = "parkId")
    @Mapping(source = "carPayJieShunDTO.carNumber", target = "plateNumber")
    @Mapping(source = "carPayJieShunDTO.parkInId", target = "accessRecordId")
    @Mapping(source = "carPayJieShunDTO.itemId", target = "payRecordId")
    @Mapping(source = "carPayJieShunDTO.inTime", target = "enterTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(source = "carPayJieShunDTO.feesTime", target = "payTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    VehiclePayRecord toVehiclePayRecord(CarPayJieShunDTO carPayJieShunDTO, Integer projectId);

    default QueryVehiclePayRecordForCountBO toQueryVehiclePayRecordForCountBO(Integer projectId, String parkId, Date payTime) {
        QueryVehiclePayRecordForCountBO queryVehiclePayRecordForCountBO = new QueryVehiclePayRecordForCountBO();
        queryVehiclePayRecordForCountBO.setProjectId(projectId);
        queryVehiclePayRecordForCountBO.setParkId(parkId);
        queryVehiclePayRecordForCountBO.setPayStartTime(payTime);
        queryVehiclePayRecordForCountBO.setPayEndTime(AboutDateUtil.datePlusHour(payTime, 1));
        return queryVehiclePayRecordForCountBO;
    }

    default PageDTO vehiclePayRecordQuery2PageDTO(VehiclePayRecordQuery vehiclePayRecordQuery) {

        PageDTO pageDTO = new PageDTO();

        if ( vehiclePayRecordQuery != null ) {
            pageDTO.setPageNumber( vehiclePayRecordQuery.getPageNumber() );
            pageDTO.setPageSize( vehiclePayRecordQuery.getPageSize() );
            pageDTO.setSortColumn( vehiclePayRecordQuery.getSortColumn() );
            pageDTO.setSortDirection( vehiclePayRecordQuery.getSortDirection() );
        }

        return pageDTO;
    }
}
